﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLDC.Common.Estate;
using System.Text;
using ZLDC.Topo.Model.Estate;

namespace ZLDC.Estate.TM
{
    public partial class EstateAdd : _PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ZLDC.Topo.BLL.Estate.SystemParamBLL.LoadParamType(sType, false, "类型");
                ZLDC.Topo.BLL.Estate.SystemParamBLL.LoadUsage(sUsage, false, "用途");
                sUsage.Items.Insert(0, "请选择");
                ZLDC.Topo.BLL.Estate.SystemParamBLL.LoadParamType(sPropertyLevel, true, "物业级别");                
                LoadAroundCondition();  // 加载周围环境
               
                LoadCity1();
                LoadCity2();
                LoadCity3();
            }
        }

        /// <summary>
        /// 加载周围环境
        /// </summary>
        private void LoadAroundCondition()
        {
            string aroundCondition = "";
            int id = _Request.GetInt("id", 0);

            if (id > 0)
            {
                EstateInfo info = ZLDC.Topo.BLL.Estate.EstateBLL.EstateDetailById(id);
                aroundCondition = info.AroundCondition;
            }

            StringBuilder sb = new StringBuilder();
            DataTable dt = ZLDC.Topo.BLL.Estate.SystemParamBLL.ListByType("周围环境");

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i % 5 == 0 && i > 0)
                        sb.Append("<br/>");

                    if (aroundCondition.Contains(dt.Rows[i]["item"].ToString()))
                        sb.Append("<input id=\"cbAroundCondition" + (i + 1) + "\" checked type=\"checkbox\" value=\"" + dt.Rows[i]["item"].ToString() + "\" onclick=\"selectedRadio(this, '" + dt.Rows[i]["item"].ToString() + "')\" />" + dt.Rows[i]["item"].ToString());
                    else
                        sb.Append("<input id=\"cbAroundCondition" + (i + 1) + "\" type=\"checkbox\" value=\"" + dt.Rows[i]["item"].ToString() + "\" onclick=\"selectedRadio(this, '" + dt.Rows[i]["item"].ToString() + "')\" />" + dt.Rows[i]["item"].ToString());
                }
            }

            spanAroundCondition.InnerHtml = sb.ToString();
        }

        /// <summary>
        /// 加载城市
        /// </summary>
        private void LoadCity1()
        {            
            ZLDC.Topo.BLL.Estate.AreaBLL.LoadCity(sCity1, 0);
        }

        /// <summary>
        /// 加载城区
        /// </summary>
        private void LoadCity2()
        {
            ZLDC.Topo.BLL.Estate.AreaBLL.LoadCity(sCity2, _Convert.ToInt(sCity1.Value, 0));
        }

        /// <summary>
        /// 加载片区
        /// </summary>
        private void LoadCity3()
        {
            ZLDC.Topo.BLL.Estate.AreaBLL.LoadCity(sCity3, _Convert.ToInt(sCity2.Value, 0));
        }
    }
}
